local SceneBase = require("app.Base.SceneBase")
local MapLayer = require("app.layer.MapLayer"):GetInstance()
local ActorManage = require("app.manage.ActorManage"):GetInstance()
local MapManage = require("app.manage.MapManage"):GetInstance()
local CastleFightScene = class("LoadingScene", SceneBase)

function CastleFightScene:ctor()
    print("CastleFightScene")
    self:initUI()
end

function CastleFightScene:onEnter()
    self.mapBg:MoveTo(cc.p(display.cx,220))
end

function CastleFightScene:initUI()
    self.bg = display.newSprite("UI/bg/bg.jpg"):addTo(self):move(display.cx,display.cy)

    self:CreatMap()

    self:AddButton()

    self:MapShow()
end

function CastleFightScene:AddButton()
    self.setButton = td.CreateBtn({map = {enabled = "UI/button/set1.png",pressed = "UI/button/set1.png",disabled = "UI/button/set1.png",} , cb = handler(self,self.setButtonClick) }):addTo(self):move(display.width-50,50):scale(1.5)
    self.quickButton = td.CreateBtn({map = {enabled = "UI/button/jiasu1.png",pressed = "UI/button/jiasu2.png",disabled = "UI/button/jiasu2.png",} , cb = handler(self,self.quickButtonClick) }):addTo(self):move(display.width-140,50):scale(1.5)
    self.mapButton = td.CreateBtn({map = {enabled = "UI/button/jian1.png",pressed = "UI/button/jian2.png",disabled = "UI/button/jian2.png",} , cb = handler(self,self.mapButtonClick) }):addTo(self):move(display.width-250,50):scale(2.5)
end

function CastleFightScene:CreatMap()
    self.mapBg = td.newScale9Sprite("UI/s9/9.png",cc.size(904-200, 404)):move(display.cx-150,-220):addTo(self)
    self.mapBg._visible = true

    self.scrollView = ccui.ScrollView:create()
    self.scrollView:move(2,-28)
    self.scrollView:setContentSize(cc.size(900-200, 430))
    self.scrollView:setDirection(2)
--    self.scrollView:setClippingEnabled(false)--裁剪

    self.scrollView:addTo(self.mapBg)

    self.Map = MapManage:GetMap()
    self.Map:move(0,30)
    self.scrollView:addChild(self.Map)

    self.scrollView:setInnerContainerSize(MapManage.size)
end

function CastleFightScene:setButtonClick()
    print("设置按钮被点击")
end

function CastleFightScene:quickButtonClick()
    print("快进按钮被点击")
end

function CastleFightScene:mapButtonClick()
    if self.mapBg._visible then --如果地图显示则隐藏
        self:MapHide()
    else
        self:MapShow()
    end
end

function CastleFightScene:MapShow()
    self.mapBg._visible = true
    self.mapButton:loadTextures("UI/button/jian1.png", "UI/button/jian2.png", "UI/button/jian2.png")
--    self.mapBg:runAction(cc.MoveBy:create(0.3, cc.p(0, 440)))

    self.mapBg:stopAllActions()
    self.mapBg:runAction(cc.MoveTo:create(0.3, cc.p(display.cx - 150, 220)))
end

function CastleFightScene:MapHide()
    self.mapBg._visible = false
    self.mapButton:loadTextures("UI/button/jia1.png", "UI/button/jia2.png", "UI/button/jia2.png")
--    self.mapBg:runAction(cc.MoveBy:create(0.3, cc.p(0, -440)))

    self.mapBg:stopAllActions()
    self.mapBg:runAction(cc.MoveTo:create(0.3, cc.p(display.cx - 150, -220)))
        
--    self:runAction(cca.seq({cca.delay(0.1),cca.cb(handler(self,self.NextCreateHistoricalRecord))}))
--    cca.seq({cca.moveTo(),cca.cb(function() 

--    end)})
end

function CastleFightScene:Update(dt)
--    if self.Contro.Play or self.Contro.Stepping then 
--        if self.Contro.Stepping then self.Contro.Stepping = false end
--        self.MapLayer:Update(dt)
--        ActorManage:Update(dt)        
--    end 
    MapManage:Update(dt)
end

return CastleFightScene